import request from '@/utils/request'

import {
  OrderDetailResponse,
  SearchParams,
  OrderListResponse,
  PayResponse,
  OrderStatusListResponse
} from './type'

enum API {
  // 创建订单
  HOSPITAL_ORDER_URL = '/order/orderInfo/auth/submitOrder/',
  // 获取订单详情
  ORDER_DETAIL_URL = '/order/orderInfo/auth/getOrderInfo/',
  // 获取所有订单信息
  ORDER_LIST_URL = '/order/orderInfo/auth',
  // 取消预约
  ORDER_CANCEL_URL = '/order/orderInfo/auth/cancelOrder/',
  // 获取支付二维码
  ORDER_PAY_URL = '/order/weixin/createNative/',
  // 查询支付结果
  ORDER_PAY_RESULT_URL = '/order/weixin/queryPayStatus/',
  // 获取订单状态
  ORDER_STATUS_URL = '/order/orderInfo/auth/getStatusList'
}

export const reqSubmitOrder = (hoscode: string, scheduleId: string, patientId: number) =>
  request.post<any, any>(API.HOSPITAL_ORDER_URL + `${hoscode}/${scheduleId}/${patientId}`)

export const reqGetOrderDetail = (id: string) =>
  request.get<any, OrderDetailResponse>(API.ORDER_DETAIL_URL + id)

export const reqGetOrderList = (data: SearchParams) =>
  request.get<any, OrderListResponse>(API.ORDER_LIST_URL + `/${data.page}/${data.limit}`, {
    params: data
  })

// 取消预约
export const reqCancelOrder = (orderId: string) =>
  request.get<any, any>(API.ORDER_CANCEL_URL + orderId)

// 获取支付二维码
export const reqGetOrderPay = (orderId: string) =>
  request.get<any, PayResponse>(API.ORDER_PAY_URL + orderId)

// 查询支付结果
export const reqGetOrderPayResult = (orderId: string) =>
  request.get<any, any>(API.ORDER_PAY_RESULT_URL + orderId)

// 获取订单状态
export const reqGetOrderStatus = () =>
  request.get<any, OrderStatusListResponse>(API.ORDER_STATUS_URL)
